package com.bjpowernode.rbac.config;

import com.bjpowernode.rbac.web.interceptor.CheckLoginInterceptor;
import com.bjpowernode.rbac.web.interceptor.CheckPermissionInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author jy
 * @version 1.0
 * @date 2022/2/13 23:15
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private CheckLoginInterceptor checkLoginInterceptor;

    @Autowired
    private CheckPermissionInterceptor checkPermissionInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        /**
         * 放行的资源
         */
        String[] excludePath = {"/css/**","/img/**","/js/**","/login.html","/user/**"};
        registry.addInterceptor(checkLoginInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(excludePath);
        registry.addInterceptor(checkPermissionInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(excludePath);
    }
}
